<?php
/**
 *   
 * ds
 * 2020.08.13
 */
namespace App\Models\MainDB;

use Illuminate\Database\Eloquent\Model;

class GiftBoxPrize extends Model{

    protected $table = 'ln_gift_box_prize';     //数据库内完整表名

    protected $primaryKey = 'id';    //主键名

    protected $fillable = [
        'id',      // 主键id
        'gift_id',  //礼物id
        'type',         // 类型：1银盒 2金盒
        'initial_weight',//初始权重
        'sold',         // 是否下架：1否 2是
        'game_type',  //
        'revise_weight',  //修正权重
        "quantity",
    ];

    public $timestamps = false;
    public function  gift(){
        return $this->hasOne('App\Models\MainDB\Gift','id','gift_id');
    }

    //获取奖品列表
    public function getChancePrizeList($type = 1) {
        $data = $this->from('ln_gift_box_prize as a')
            ->select('a.id', 'a.initial_weight', 'a.type', 'a.gift_id', 'b.name as gift_name', 'b.price', 'b.picture', 'b.special', 'a.quantity')
            ->leftJoin('ln_gift as b', 'a.gift_id', '=', 'b.id')
            ->where(['a.type' => $type])
            ->get()->toArray();
        return $data;
    }

}